package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.PubLine;
import com.ruoyi.bussiness.service.IPubLineService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线路Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/line")
public class PubLineController extends BaseController
{
    private String prefix = "bussiness/line";

    @Autowired
    private IPubLineService pubLineService;

    @RequiresPermissions("bussiness:line:view")
    @GetMapping()
    public String line()
    {
        return prefix + "/line";
    }

    /**
     * 查询线路列表
     */
    @RequiresPermissions("bussiness:line:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PubLine pubLine)
    {
        startPage();
        List<PubLine> list = pubLineService.selectPubLineList(pubLine);
        return getDataTable(list);
    }

    /**
     * 导出线路列表
     */
    @RequiresPermissions("bussiness:line:export")
    @Log(title = "线路", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PubLine pubLine)
    {
        List<PubLine> list = pubLineService.selectPubLineList(pubLine);
        ExcelUtil<PubLine> util = new ExcelUtil<PubLine>(PubLine.class);
        return util.exportExcel(list, "线路数据");
    }

    /**
     * 新增线路
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存线路
     */
    @RequiresPermissions("bussiness:line:add")
    @Log(title = "线路", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PubLine pubLine)
    {
        return toAjax(pubLineService.insertPubLine(pubLine));
    }

    /**
     * 修改线路
     */
    @RequiresPermissions("bussiness:line:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PubLine pubLine = pubLineService.selectPubLineById(id);
        mmap.put("pubLine", pubLine);
        return prefix + "/edit";
    }

    /**
     * 修改保存线路
     */
    @RequiresPermissions("bussiness:line:edit")
    @Log(title = "线路", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PubLine pubLine)
    {
        return toAjax(pubLineService.updatePubLine(pubLine));
    }

    /**
     * 删除线路
     */
    @RequiresPermissions("bussiness:line:remove")
    @Log(title = "线路", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pubLineService.deletePubLineByIds(ids));
    }
}
